
import nodejs from "@feidao/web/atom/browser/msg/nodejs";
import { file_url, send_msg, spaceid } from './config';
export default async function file_upload(file: File) {
	const file_name = file.name;
	const r = new FileReader();
	r.readAsDataURL(file);
	return new Promise((resolve, reject) => {
		r.onload = async function (e) {
			const data = (e.target as any).result as string;
			const res = await nodejs(send_msg, 'web/past_papers/file_upload', { host: file_url, spaceid, data, file_name }, false, false);
			resolve(res);
		}
		r.onerror = async function (e) {
			reject('fail');
		}
	});
}